/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.bht.esa.weather.model.geo;

import java.io.Serializable;

/**
 * Kapselt Breiten- und Längengrad in eine Koordinaten-Klasse
 * 
 * @author Andreas Goese
 * @author Sven Höche
 */
public class GeoCoordinates implements Serializable {
    private static final long serialVersionUID = 1234567891281000007L;

    private double lat;
    private double lon;

    public GeoCoordinates() {
    }

    public GeoCoordinates(double lat, double lon) {
        this.lat = lat;
        this.lon = lon;
    }
    
    public GeoCoordinates(String coordinates) throws IllegalArgumentException{
        if(!coordinates.matches("^-{0,1}\\d{1,2}\\.\\d+,-{0,1}\\d{1,2}\\.\\d+$")){
            throw new IllegalArgumentException("Coordinates-String does not match to given format");
        }
        
        String[] coordinateParts = coordinates.split(",");
        if(coordinateParts.length != 2){
            throw new IllegalArgumentException("Coordinates-String does not match to given format");
        }
        
        try{
            this.lat = Double.parseDouble(coordinateParts[0]);
            this.lon = Double.parseDouble(coordinateParts[1]);
        }catch(NumberFormatException e){
            throw new IllegalArgumentException("Coordinates-String does not match to given format");
        }
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLon() {
        return lon;
    }

    public void setLon(double lon) {
        this.lon = lon;
    }

    @Override
    public String toString() {
        return +this.lat+","+this.lon;
    }

}
